<?php

namespace App\Http\Controllers\User;

use App\Http\Controllers\Controller;
use App\Models\Order;
use Illuminate\Http\Request;
use App\Http\Resources\OrderResource;




class OrderController extends Controller
{
    /**
     * 订单页面
     *
     * @return \Illuminate\Http\Response
     */
    public function index()
    {

        return view('user.order.orderList');
    }

    /**
     * 快递信息查询
     *
     * @return \Illuminate\Http\Response
     */
    public function create(Request $request)
    {
        if (empty($request->number)) return ;
        $result = LogisticsQuery($request->number);

        return response()->json($result);
    }


    /**
     * 订单条件搜索
     *
     * @param  \Illuminate\Http\Request  $request
     * @return \Illuminate\Http\Response
     */
    public function store(Request $request, Order $order)
    {
        list($limit , $where , $verify , $exclude) = $order->SearchHandler($request);

        $response = $order->where('user_id' , auth()->id())
            ->when($verify , function($query) use ($where){
                $query->where($where);
            })->when(isset($exclude['created_at']),function($query) use ($exclude){
                $time = explodeString('/' , $exclude['created_at']);
                $query->whereBetween('created_at',[$time[0],$time[1].' 23:59:59']);
            })->paginate($limit);

        return new OrderResource($order->requestLayuiData($response));
    }


    /**
     * 订单详情
     *
     * @param  \App\Order  $order
     * @return \Illuminate\Http\Response
     */
    public function show(Request $request, Order $order)
    {

        return view('user.order.order_info',compact('order'));
    }

    /**
     * Show the form for editing the specified resource.
     *
     * @param  \App\Order  $order
     * @return \Illuminate\Http\Response
     */
    public function edit(Order $order)
    {
        //
    }

    /**
     * Update the specified resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  \App\Order  $order
     * @return \Illuminate\Http\Response
     */
    public function update(Request $request, Order $order)
    {
        //
    }

    /**
     * Remove the specified resource from storage.
     *
     * @param  \App\Order  $order
     * @return \Illuminate\Http\Response
     */
    public function destroy(Order $order)
    {
        //
    }
}
